package com.ruoyi.rental.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.rental.domain.RentalAgreementsByName;
import com.ruoyi.rental.service.IRentalAgreementsByNameService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 租约管理Controller
 * 
 * @author ruoyi
 * @date 2024-10-15
 */
@RestController
@RequestMapping("/rental/rental")
public class RentalAgreementsByNameController extends BaseController
{
    @Autowired
    private IRentalAgreementsByNameService rentalAgreementsByNameService;

    /**
     * 查询租约管理列表
     */
    @PreAuthorize("@ss.hasPermi('rental:rental:list')")
    @GetMapping("/list")
    public TableDataInfo list(RentalAgreementsByName rentalAgreementsByName)
    {
        startPage();
        List<RentalAgreementsByName> list = rentalAgreementsByNameService.selectRentalAgreementsByNameList(rentalAgreementsByName);
        return getDataTable(list);
    }

    /**
     * 导出租约管理列表
     */
    @PreAuthorize("@ss.hasPermi('rental:rental:export')")
    @Log(title = "租约管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, RentalAgreementsByName rentalAgreementsByName)
    {
        List<RentalAgreementsByName> list = rentalAgreementsByNameService.selectRentalAgreementsByNameList(rentalAgreementsByName);
        ExcelUtil<RentalAgreementsByName> util = new ExcelUtil<RentalAgreementsByName>(RentalAgreementsByName.class);
        util.exportExcel(response, list, "租约管理数据");
    }

    /**
     * 获取租约管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('rental:rental:query')")
    @GetMapping(value = "/{rentalId}")
    public AjaxResult getInfo(@PathVariable("rentalId") Long rentalId)
    {
        return success(rentalAgreementsByNameService.selectRentalAgreementsByNameByRentalId(rentalId));
    }

    /**
     * 新增租约管理
     */
    @PreAuthorize("@ss.hasPermi('rental:rental:add')")
    @Log(title = "租约管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody RentalAgreementsByName rentalAgreementsByName)
    {
        return toAjax(rentalAgreementsByNameService.insertRentalAgreementsByName(rentalAgreementsByName));
    }

    /**
     * 修改租约管理
     */
    @PreAuthorize("@ss.hasPermi('rental:rental:edit')")
    @Log(title = "租约管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody RentalAgreementsByName rentalAgreementsByName)
    {
        return toAjax(rentalAgreementsByNameService.updateRentalAgreementsByName(rentalAgreementsByName));
    }

    /**
     * 删除租约管理
     */
    @PreAuthorize("@ss.hasPermi('rental:rental:remove')")
    @Log(title = "租约管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{rentalIds}")
    public AjaxResult remove(@PathVariable Long[] rentalIds)
    {
        return toAjax(rentalAgreementsByNameService.deleteRentalAgreementsByNameByRentalIds(rentalIds));
    }
}
